//
//  CZSearchBar.m
//  小和微博
//
//  Created by 董晓合 on 15/2/21.
//  Copyright (c) 2015年 itcast. All rights reserved.
//

#import "CZSearchBar.h"

@implementation CZSearchBar

// 通过代码创建控件时会调用
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setup];
    }
    return self;
}



// 通过xib/Storboard创建时调用
- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        [self setup];
    }
    return self;
}

- (void)setup
{
    // 一次性的初始化
    // 设置边框样式
    self.borderStyle = UITextBorderStyleRoundedRect;
    // 设置提醒文本
    self.placeholder = @"请输入您想搜索的任意内容";
    
    // 设置右边的图标
    UIImageView *icon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"searchbar_searchlist_search_icon"]];
    self.leftView = icon;
    self.leftViewMode = UITextFieldViewModeAlways;
    
    // 设置清除按钮
    self.clearButtonMode = UITextFieldViewModeAlways;
}

- (void)setLeftIconName:(NSString *)leftIconName {

    _leftIconName = leftIconName;
    UIImageView *icon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:leftIconName]];
    icon.width = 30;
    icon.contentMode = UIViewContentModeCenter;
    self.leftView = icon;

}

@end
